package com.dongjiantong.quarantine.serviceImpl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.dongjiantong.biz.enums.ReportType;
import com.dongjiantong.biz.model.EarMarkLife;
import com.dongjiantong.biz.model.ReportHandleResumes;
import com.dongjiantong.biz.model.Stables;
import com.dongjiantong.biz.service.*;
import com.dongjiantong.common.utils.ReportNumberMakerUtil;
import com.dongjiantong.common.web.sso.LoginInfo;
import com.dongjiantong.farmrecords.model.FarmRecordsProduction;
import com.dongjiantong.farmrecords.service.FarmRecordsProductionService;
import com.dongjiantong.mybatis.ServiceMybatis;
import com.dongjiantong.quarantine.enums.DjtBreedReportsStatus;
import com.dongjiantong.quarantine.enums.DjtButcherAdmissionInspectionsStatus;
import com.dongjiantong.quarantine.enums.FileType;
import com.dongjiantong.quarantine.enums.HarmlessStatus;
import com.dongjiantong.quarantine.mapper.BreedReportsFileMapper;
import com.dongjiantong.quarantine.mapper.DjtBreedReportsMapper;
import com.dongjiantong.quarantine.mapper.DjtButcherAdmissionInspectionsMapper;
import com.dongjiantong.quarantine.mapper.HarmlessMapper;
import com.dongjiantong.quarantine.model.BreedReportsFile;
import com.dongjiantong.quarantine.model.DjtBreedReports;
import com.dongjiantong.quarantine.model.DjtButcherAdmissionInspections;
import com.dongjiantong.quarantine.model.Harmless;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by mz on 13/11/17.
 *
 */
@Slf4j
@Service(version = "1.0.0")
public class DjtBreedReportsWriteServiceImpl extends ServiceMybatis<DjtBreedReports> implements DjtBreedReportsWriteService{

    @Resource
    private DjtBreedReportsMapper djtBreedReportsMapper;

    @Reference(version = "1.0.0")
    private FarmRecordsProductionService farmRecordsProductionService;

    @Resource
    private DjtButcherAdmissionInspectionsMapper djtButcherAdmissionInspectionsMapper;

    @Resource
    private BreedReportsFileMapper breedReportsFileMapper;

    @Resource
    private HarmlessMapper harmlessMapper;

    @Reference(version = "1.0.0")
    private StablesService stablesService;

    @Reference(version = "1.0.0")
    private EarMarksWriteService earMarksWriteService;

    @Reference(version = "1.0.0")
    private EarMarkLifeWriteService earMarkLifeWriteService;

    @Reference(version = "1.0.0")
    private FarmStockService farmStockService;

    @Reference(version = "1.0.0")
    private ReportHandleResumesService reportHandleResumesService;


    /**
     * 创建单据
     *
     * @param djtBreedReports 单据对象
     * @param toStatus 到状态
     * @return Map<String , Object>（id）
     */
    @Override
    public Map<String , Object> create(DjtBreedReports djtBreedReports,Integer toStatus,LoginInfo loginInfo) {
        Map<String , Object> result = Maps.newHashMap();
        Integer fromStatus = djtBreedReports.getStatus().intValue();
        String prefix = "N";

        prefix = ReportNumberMakerUtil.createPrefix(prefix,loginInfo.getProvinceId(),loginInfo.getCityId(),loginInfo.getRegionId());//单据编号前缀的开头字母 和 当前用户

        String number = ReportNumberMakerUtil.create(prefix,djtBreedReportsMapper.findCurrentMaxNumber(prefix));

        djtBreedReports.setNumber(number);
        djtBreedReports.setDelete_flag(1);

        if(toStatus != null && !fromStatus.equals(toStatus)){

            djtBreedReports.setStatus(toStatus.byteValue());
            djtBreedReportsMapper.insert(djtBreedReports);

            ReportHandleResumes reportHandleResumes = new ReportHandleResumes();

            reportHandleResumes.setFrom_status(fromStatus.byteValue());
            reportHandleResumes.setReport_id(djtBreedReports.getId());
            reportHandleResumes.setReport_number(number);
            reportHandleResumes.setTo_status(toStatus.byteValue());
            reportHandleResumes.setType(ReportType.QUARANTINE_ORIGIN_AREA.value());
            reportHandleResumes.setCreated_at(new Date());
            reportHandleResumes.setUpdated_at(new Date());
            reportHandleResumes.setUser_id(loginInfo.getId());
            reportHandleResumes.setUser_name(loginInfo.getRealName());

            reportHandleResumesService.create(reportHandleResumes);

        }else {
            djtBreedReportsMapper.insert(djtBreedReports);
        }
        List<String> earTagNumbers = djtBreedReports.getEar_tag_numbers();
        List<EarMarkLife> earMarkLives = null;
        for(String earTagNumber : earTagNumbers){
            earMarkLives = new ArrayList<>();
            EarMarkLife earMarkLife = new EarMarkLife();

            earMarkLife.setMark_number(earTagNumber);
            earMarkLife.setReport_id(djtBreedReports.getId());
            earMarkLife.setReport_name(djtBreedReports.getNumber());
            earMarkLife.setReport_type(ReportType.QUARANTINE_ORIGIN_AREA.value());
            earMarkLife.setMark_type(djtBreedReports.getAnimal_second_type());
            earMarkLife.setOperator_id(loginInfo.getId());
            earMarkLife.setOperator_name(loginInfo.getRealName());
            earMarkLife.setIs_selected(1);
            earMarkLife.setCreated_at(new Date());

            earMarkLives.add(earMarkLife);
        }
        earMarkLifeWriteService.insertList(earMarkLives);
        if(!earTagNumbers.isEmpty()){
            earMarksWriteService.updateMarks(addEarIsSelectedParam(earTagNumbers));
        }
        result.put("id",djtBreedReports.getId());
        return result;
    }

    /**
     * 更新单据
     *
     * @param djtBreedReports 单据对象
     * @param toStatus 到状态
     * @return Boolean （是否更新成功）
     */
    @Override
    public Map<String , Object> update(DjtBreedReports djtBreedReports,Integer toStatus,LoginInfo loginInfo) {
        Integer fromStatus = djtBreedReports.getStatus().intValue();
        Long id = djtBreedReports.getId();
        Boolean isSuccess = false;
        Map<String , Object> resultMap = Maps.newHashMap();
        djtBreedReports.setDelete_flag(1);
        if(toStatus != null && !fromStatus.equals(toStatus)){
            if(toStatus.equals(DjtBreedReportsStatus.UNCOMMITTED.value())){
                List<String> earTagNumbersPre = earMarkLifeWriteService.findListByBreedReportId(getParamMapOfEarLifeQuery(id));
                if(earTagNumbersPre != null && !earTagNumbersPre.isEmpty()){
                    earMarksWriteService.updateMarks(clearEarIsSelectedParam(earTagNumbersPre));
                }
            }else if (toStatus.equals(DjtBreedReportsStatus.STAY_APPROVE.value())){
                earMarksWriteService.updateMarks(addEarIsSelectedParam(djtBreedReports.getEar_tag_numbers()));
            }

            djtBreedReports.setStatus(toStatus.byteValue());
            isSuccess = djtBreedReportsMapper.updateByPrimaryKey(djtBreedReports) == 1;

            ReportHandleResumes reportHandleResumes = new ReportHandleResumes();

            reportHandleResumes.setFrom_status(fromStatus.byteValue());
            reportHandleResumes.setReport_id(djtBreedReports.getId());
            reportHandleResumes.setReport_number(djtBreedReports.getNumber());
            reportHandleResumes.setTo_status(toStatus.byteValue());
            reportHandleResumes.setType(ReportType.QUARANTINE_ORIGIN_AREA.value());
            reportHandleResumes.setCreated_at(new Date());
            reportHandleResumes.setUpdated_at(new Date());
            reportHandleResumes.setUser_id(loginInfo.getId());
            reportHandleResumes.setUser_name(loginInfo.getRealName());

            reportHandleResumesService.create(reportHandleResumes);

            if(toStatus.equals(DjtBreedReportsStatus.HAS_LICENSE.value())) {
                if (Strings.isNullOrEmpty(djtBreedReports.getSource_json())) {
                    List<Map<String, Object>> from_stables = djtBreedReports.getFrom_stables();
                    if (from_stables == null || from_stables.isEmpty()) {
                        farmRecordsProductionService.insert(buildProduction(djtBreedReports, null, null, null,loginInfo));
                    } else {
                        for (Map<String, Object> stableInfo : from_stables) {
                            farmRecordsProductionService.insert(buildProduction(djtBreedReports, ((Integer) stableInfo.get("stableId")).longValue(), (String) stableInfo.get("stableNumber"), (Integer) stableInfo.get("stableQuantity"),loginInfo));
                            Stables stables = new Stables();
                            stables.setId(((Integer) stableInfo.get("stableId")).longValue());
                            stables.setQuantity(0 - djtBreedReports.getQuantity());
                            stablesService.updateSC(stables);
                        }
                    }
                    Map<String , Object> stockUpdateParamsMap = Maps.newHashMap();
                    stockUpdateParamsMap.put("farmId",djtBreedReports.getFarm_id());
                    stockUpdateParamsMap.put("changeQuantity",0 - djtBreedReports.getQuantity());
                    farmStockService.updateByFarmId(stockUpdateParamsMap);
                }
                List<String> earTagNumbers = djtBreedReports.getEar_tag_numbers();
                if(earTagNumbers == null || earTagNumbers.isEmpty()){
                    earTagNumbers = earMarkLifeWriteService.findListByBreedReportId(getParamMapOfEarLifeQuery(id));
                }
                earMarksWriteService.updateMarks(outEarParam(earTagNumbers));

                if (djtBreedReports.getIs_to_local() == 2) {
                    DjtButcherAdmissionInspections djtButcherAdmissionInspections = buildAdmission(djtBreedReports,loginInfo);
                    djtButcherAdmissionInspectionsMapper.insert(djtButcherAdmissionInspections);
                    List<EarMarkLife> earMarkLives = null;
                    for(String earTagNumber : earTagNumbers){
                        earMarkLives = new ArrayList<>();
                        EarMarkLife earMarkLife = new EarMarkLife();

                        earMarkLife.setMark_number(earTagNumber);
                        earMarkLife.setReport_id(djtButcherAdmissionInspections.getId());
                        earMarkLife.setReport_name(djtButcherAdmissionInspections.getNumber());
                        earMarkLife.setReport_type(ReportType.ADMISSION_INSPECTION.value());
                        earMarkLife.setMark_type(djtBreedReports.getAnimal_second_type());
                        earMarkLife.setOperator_id(loginInfo.getId());
                        earMarkLife.setOperator_name(loginInfo.getRealName());
                        earMarkLife.setIs_selected(1);
                        earMarkLife.setCreated_at(new Date());

                        earMarkLives.add(earMarkLife);
                    }
                    earMarkLifeWriteService.insertList(earMarkLives);
                    writeFiles(ReportType.ADMISSION_INSPECTION.value(), FileType.PHOTO.value(),djtButcherAdmissionInspections.getId(),djtBreedReports.getQuarantine_cert_photo_list(),"quarantine_cert_photo_list" , "入场-产地检疫证照片");

                }
                Integer harmlessQuantity = djtBreedReports.getHarmless_treatment_quantity();
                if(harmlessQuantity > 0){
                    Harmless harmless = buildHarmless(djtBreedReports,loginInfo);
                    harmlessMapper.insert(harmless);
                    resultMap.put("harmlessId",harmless.getId());
                    djtBreedReports.setHarmless_id(harmless.getId());
                    djtBreedReports.setHarmless_number(harmless.getNumber());
                    djtBreedReportsMapper.updateByPrimaryKey(djtBreedReports);
                }
                writeFiles(ReportType.QUARANTINE_ORIGIN_AREA.value(),FileType.PHOTO.value(),id,djtBreedReports.getQuarantine_cert_photo_list(),"quarantine_cert_photo_list" , "产地检疫发证");
            }

            if(toStatus.equals(DjtBreedReportsStatus.DISAPPROVE.value())){

                List<String> earTagNumbers = djtBreedReports.getEar_tag_numbers();
                if(earTagNumbers == null || earTagNumbers.isEmpty()){
                    earTagNumbers = earMarkLifeWriteService.findListByBreedReportId(getParamMapOfEarLifeQuery(id));
                }

                earMarksWriteService.updateMarks(clearEarIsSelectedParam(earTagNumbers));

                earMarkLifeWriteService.deleteByReportIdAndType(getParamMapOfEarLifeQuery(id));
            }
            if(toStatus.equals(DjtBreedReportsStatus.STAY_LICENSE.value())){
                writeFiles(ReportType.QUARANTINE_ORIGIN_AREA.value(),1,id,djtBreedReports.getSite_survey_photo_list() , "site_survey_photo_list","产地检疫勘察");
            }
        }else {
            List<String> earTagNumbersPre = earMarkLifeWriteService.findListByBreedReportId(getParamMapOfEarLifeQuery(id));
            if(earTagNumbersPre != null && !earTagNumbersPre.isEmpty()){
                earMarkLifeWriteService.deleteByReportIdAndType(getParamMapOfEarLifeQuery(id));
                earMarksWriteService.updateMarks(clearEarIsSelectedParam(earTagNumbersPre));
                List<String> earTagNumbers = djtBreedReports.getEar_tag_numbers();
                List<EarMarkLife> earMarkLives = null;
                for(String earTagNumber : earTagNumbers){
                    earMarkLives = new ArrayList<>();
                    EarMarkLife earMarkLife = new EarMarkLife();

                    earMarkLife.setMark_number(earTagNumber);
                    earMarkLife.setReport_id(djtBreedReports.getId());
                    earMarkLife.setReport_name(djtBreedReports.getNumber());
                    earMarkLife.setReport_type(ReportType.QUARANTINE_ORIGIN_AREA.value());
                    earMarkLife.setMark_type(djtBreedReports.getAnimal_second_type());
                    earMarkLife.setOperator_id(loginInfo.getId());
                    earMarkLife.setOperator_name(loginInfo.getRealName());
                    earMarkLife.setIs_selected(1);
                    earMarkLife.setCreated_at(new Date());

                    earMarkLives.add(earMarkLife);
                }
                earMarkLifeWriteService.insertList(earMarkLives);
                if(!earTagNumbers.isEmpty()){
                    earMarksWriteService.updateMarks(addEarIsSelectedParam(earTagNumbers));
                }
                isSuccess = djtBreedReportsMapper.updateByPrimaryKey(djtBreedReports) == 1;
            }
        }

        resultMap.put("isSuccess",isSuccess);

        return resultMap;
    }

    /**
     * 更改单据的delete——flag
     *
     * @param id 单据id
     */
    @Override
    public void updateDeleteFlag(Long id) {
        djtBreedReportsMapper.updateDeleteFlag(id);
    }

    /**
     * 图片或文件的写入
     * @param fileUrls 照片的url
     * @param field 字段名
     * @param state 意义
     */
    private void writeFiles(Integer type1 , Integer type2 ,Long relevanceId ,List<String> fileUrls , String field, String state){
        if(fileUrls != null && !fileUrls.isEmpty()){
            for(String string : fileUrls){
                BreedReportsFile breedReportsFile = new BreedReportsFile();
                breedReportsFile.setType1(type1);
                breedReportsFile.setType2(type2);
                breedReportsFile.setField(field);
                breedReportsFile.setAddress(string);
                breedReportsFile.setRelevance_id(relevanceId);
                breedReportsFile.setState(state);
                breedReportsFile.setDate(new Date());
                breedReportsFileMapper.insert(breedReportsFile);
            }
        }
    }

    /**
     * 查询该单据耳标的list的参数
     * @param reportId 单据id
     * @return Map<String,Object>
     */
    private Map<String , Object> getParamMapOfEarLifeQuery(Long reportId){
        Map<String , Object> map = Maps.newHashMap();
        map.put("reportId",reportId);
        map.put("reportType", ReportType.QUARANTINE_ORIGIN_AREA.value());
        return map;
    }

    /**
     * 清除耳标的参数
     * @param earTagNumbers 耳标list
     * @return Map<String , Object>
     */
    private Map<String , Object> clearEarIsSelectedParam(List<String> earTagNumbers){
        Map<String , Object> map = Maps.newHashMap();
        map.put("earTagNumbers",earTagNumbers);
        map.put("isSelected",1);

        return map;
    }

    /**
     * 选择耳标的参数
     * @param earTagNumbers 耳标list
     * @return Map<String , Object>
     */
    private Map<String , Object> addEarIsSelectedParam(List<String> earTagNumbers){
        Map<String,Object> map = Maps.newHashMap();
        map.put("earTagNumbers",earTagNumbers);
        map.put("isSelected",2);
        return map;
    }

    /**
     * 出库耳标的参数
     * @param earTagNumbers 耳标list
     * @return Map<String , Object>
     */
    private Map<String , Object> outEarParam(List<String> earTagNumbers){
        Map<String,Object> earMap = Maps.newHashMap();
        earMap.put("earTagNumbers",earTagNumbers);
        earMap.put("status",3);
        earMap.put("woreAt",new Date());

        return earMap;
    }

    /**
     * 创建无害化对象
     * @param djtBreedReports 产地检疫的对象
     * @return Harmless
     */
    private Harmless buildHarmless(DjtBreedReports djtBreedReports,LoginInfo loginUser) {

        Harmless harmless = new Harmless();

        String prefix = "WN";
        prefix = ReportNumberMakerUtil.createPrefix(prefix,loginUser.getProvinceId(),loginUser.getCityId(),loginUser.getRegionId());

        String number = ReportNumberMakerUtil.create(prefix,harmlessMapper.findCurrentMaxNumber(prefix));

        harmless.setNumber(number);
        harmless.setReport_id(djtBreedReports.getId());
        harmless.setReport_number(djtBreedReports.getNumber());
        harmless.setReport_type(ReportType.QUARANTINE_ORIGIN_AREA.value());
        harmless.setFarm_id(djtBreedReports.getFarm_id());
        harmless.setFarm_name(djtBreedReports.getFarm_name());
        harmless.setAnimal_type(djtBreedReports.getAnimal_second_type());
        harmless.setAnimal_type_name(djtBreedReports.getAnimal_second_type_name());
        harmless.setUnit(djtBreedReports.getUnit().intValue());
        harmless.setApply_station_id(djtBreedReports.getApply_station_id());
        harmless.setApply_station_name(djtBreedReports.getApply_station_name());
        harmless.setButcher_farm_name(djtBreedReports.getButcher_farm_name());
        harmless.setIs_local(djtBreedReports.getIs_to_local().intValue());
        harmless.setDelete_flag(1);
        harmless.setQuantity(djtBreedReports.getHarmless_treatment_quantity().floatValue());
        harmless.setFactory_owner_id(djtBreedReports.getUser_id());
        harmless.setFactory_owner_name(djtBreedReports.getUser_name());
        harmless.setTreatment(djtBreedReports.getHarmless_treatment());
        harmless.setStatus(HarmlessStatus.UNCOMMITTED.value());
        harmless.setQuarantine_user_id(loginUser.getId());
        harmless.setQuarantine_user_name(loginUser.getRealName());
        harmless.setDelete_flag(1);
        harmless.setCreated_at(new Date());
        harmless.setUpdated_at(new Date());
        return harmless;
    }

    /**
     * 生成入场监督检查的单据（产地检疫发证是自动生成）
     * ()
     * @return 入场监督检查的对象
     */
    private DjtButcherAdmissionInspections buildAdmission(DjtBreedReports djtBreedReports,LoginInfo loginUser) {

        DjtButcherAdmissionInspections djtButcherAdmissionInspections = new DjtButcherAdmissionInspections();

        djtButcherAdmissionInspections.setNumber(djtBreedReports.getNumber());
        djtButcherAdmissionInspections.setButcher_farm_id(djtBreedReports.getButcher_farm_id());
        djtButcherAdmissionInspections.setButcher_farm_name(djtBreedReports.getButcher_farm_name());
        djtButcherAdmissionInspections.setButcher_selected(-1);
        djtButcherAdmissionInspections.setDate(new Date());
        djtButcherAdmissionInspections.setStatus(DjtButcherAdmissionInspectionsStatus.UNCOMMITTED.value().byteValue());

        djtButcherAdmissionInspections.setUnit(djtBreedReports.getUnit().intValue());
        djtButcherAdmissionInspections.setUser_id(loginUser.getId());
        djtButcherAdmissionInspections.setUser_name(loginUser.getRealName());
        djtButcherAdmissionInspections.setFarm_report_id(djtBreedReports.getId());
        djtButcherAdmissionInspections.setFarm_report_number(djtBreedReports.getNumber());
        djtButcherAdmissionInspections.setQuantity(djtBreedReports.getQualified_quantity());
        djtButcherAdmissionInspections.setQualified_quantity(0);
        djtButcherAdmissionInspections.setProduct_type(djtBreedReports.getAnimal_type());
        djtButcherAdmissionInspections.setOwner(djtBreedReports.getOwner());
        djtButcherAdmissionInspections.setOwner_mobile(djtBreedReports.getOwner_mobile());
        djtButcherAdmissionInspections.setSource_id(djtBreedReports.getFarm_id());
        djtButcherAdmissionInspections.setSource_name(djtBreedReports.getFarm_name());
        djtButcherAdmissionInspections.setIs_local(djtBreedReports.getIs_to_local().intValue());
        djtButcherAdmissionInspections.setRemainder(djtBreedReports.getQualified_quantity());
        djtButcherAdmissionInspections.setClinical_examination(djtBreedReports.getExamination());
        djtButcherAdmissionInspections.setHas_animal_identify(djtBreedReports.getHas_animal_identify());
        djtButcherAdmissionInspections.setQuarantine_cert_number(djtBreedReports.getQuarantine_cert_number());
        djtButcherAdmissionInspections.setQualified_quantity(djtBreedReports.getQualified_quantity());
        djtButcherAdmissionInspections.setUnqualified_quantity(0);
        djtButcherAdmissionInspections.setSlaughterings(0);
        djtButcherAdmissionInspections.setDelete_flag(1);
        djtButcherAdmissionInspections.setCreated_at(new Date());
        djtButcherAdmissionInspections.setUpdated_at(new Date());
        return djtButcherAdmissionInspections;
    }

    /**
     * build production
     * @param djtBreedReports 产地检疫对象
     * @param stableId 栏舍id
     * @param stableNumber 栏舍编号
     * @param stableQuantity 数量
     * @return FarmRecordsProduction
     */
    private FarmRecordsProduction buildProduction(DjtBreedReports djtBreedReports,Long stableId, String stableNumber,Integer stableQuantity,LoginInfo loginInfo) {
        FarmRecordsProduction farmRecordsProduction = new FarmRecordsProduction();

        Integer animal_type = djtBreedReports.getAnimal_type();
        Integer animal_second_type = 0;
        Integer animal_third_type = 0;
        String prefix = "SSC";
        prefix = ReportNumberMakerUtil.createPrefix(prefix,loginInfo.getProvinceId(),loginInfo.getCityId(),loginInfo.getRegionId());//单据编号前缀的开头字母 和 当前用户
        String number = ReportNumberMakerUtil.create(prefix,farmRecordsProductionService.findCurrentMaxNumber(prefix));//要在表中拿到当前最大的Number号
        farmRecordsProduction.setNumber(number);
        farmRecordsProduction.setStable_number(stableNumber);
        farmRecordsProduction.setRelate_id(djtBreedReports.getId());
        farmRecordsProduction.setRelate_number(djtBreedReports.getNumber());
        farmRecordsProduction.setBreed_type(animal_type);
        if(stableId != null){
            Stables stables = stablesService.selectByPrimaryKey(stableId);
            animal_second_type = stables.getAnimal_TwoType();
            animal_third_type = stables.getAnimal_ThreeType();
            farmRecordsProduction.setBreed_second_type(animal_second_type);
            farmRecordsProduction.setBreed_third_type(animal_third_type);
            farmRecordsProduction.setChange_quantity(0-stableQuantity);
            farmRecordsProduction.setOut_quantity(stableQuantity);
            farmRecordsProduction.setArea(Integer.valueOf(stables.getBreed_area()));
        }else {
            animal_second_type = djtBreedReports.getAnimal_second_type();
            animal_third_type = djtBreedReports.getAnimal_third_type();
            farmRecordsProduction.setOut_quantity(djtBreedReports.getQuantity());
            farmRecordsProduction.setChange_quantity( 0 - djtBreedReports.getQuantity());
        }
        farmRecordsProduction.setBirth_quantity(animal_second_type);
        farmRecordsProduction.setBreed_third_type(animal_third_type);
        farmRecordsProduction.setIn_quantity(0);
        farmRecordsProduction.setBirth_quantity(0);
        farmRecordsProduction.setFarm_id(djtBreedReports.getFarm_id());
        farmRecordsProduction.setFarm_name(djtBreedReports.getFarm_name());
        farmRecordsProduction.setDeath_quantity(0);
        farmRecordsProduction.setDate(new Date());
        farmRecordsProduction.setUnit(djtBreedReports.getUnit().intValue());
        farmRecordsProduction.setStatus(1);
        farmRecordsProduction.setDelete_flag(1);
        farmRecordsProduction.setCreated_at(new Date());
        farmRecordsProduction.setUpdated_at(new Date());
        return farmRecordsProduction;
    }

}
